package com.aletto.general_store.data.network;

import com.aletto.general_store.utils.LocalConfigStore;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class CommonParameterInterceptor implements Interceptor {

    @NotNull
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request originalRequest = chain.request();
        Request.Builder requestBuilder = addHeaders(originalRequest);
        return chain.proceed(requestBuilder.build());
    }


    private Request.Builder addHeaders(Request request) {
        Request.Builder requestHeader = request.newBuilder()
                .header("os", "android")
                // cn-简体中文；en-英语；jpn-日本；tc-繁体中文（默认cn）
                .header("language", "cn")
                .header("version-name", "BuildConfig.VERSION_NAME")
                .header("version-code", String.valueOf(1));

        // 登录 token
        String userToken = LocalConfigStore.getInstance().getToken();
        if (userToken != null && !userToken.isEmpty()){
            requestHeader.header("Authorization", userToken);
        }
//
//        // 设备唯一ID
//        String deviceId = PushAgent.getInstance(MetaEraApplication.sInstance).getRegistrationId();
//        if (deviceId != null){
//            requestHeader.header("device-id", deviceId);
//        }

        return requestHeader;
    }


}
